#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 20 18:16:27 2024

@author: Nicholas Drachman
"""


import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['pdf.fonttype'] = 42
plt.rcParams['svg.fonttype'] = 'none'


p0 = 17.5/2 * 133.32 # water vapor pressure in pascals (using water vapor pressure at 20 C from CRC handbook)
p_bg = 7e-8 * 133.32  # background pressure in pascals
r0 = 30e-9 # radius of meniscus
rf = 550e-9
a_i = 7e-10  # kinetic radius of amino acid with solvation shell
a_w = 1.3e-10  # kinetic radius of water molecule
a_bg = 1.8e-10  # kinetic radius of N2 moleucle
kB = 1.38e-23  # Boltzmann constant
T = 300
Na = 6.022e23
r = np.linspace(r0,rf,1000)

sigma_w = np.pi*(a_i+a_w)**2
sigma_bg = np.pi*(a_i+a_bg)**2



n0 = p0/(kB*T)
nbg = p_bg/(kB*T)

Pc = 1-np.exp((-sigma_w*n0*r0**2 * (1/r0 - 1/r)))
Pc_bg = 1-np.exp((-sigma_bg*nbg*(r-r0)))
Pc_total = 1-np.exp((-sigma_w*n0*r0**2 * (1/r0 - 1/r) - sigma_bg*nbg*(r-r0)))

n0 = p0/(kB*T)
nbg = p_bg/(kB*T)
n = n0*r0**2 / r**2 + nbg
n = n/Na*1e3

pressure = p0*r0**2 / r**2 + p_bg

color1 = 'k'

fig, ax1 = plt.subplots(figsize = [5,4])
ax1.plot((r-r0)*1e9,Pc_total*100,color = color1)
ax1.set_ylabel('cumulative collision probability', color = color1, fontsize = 14)
ax1.tick_params(axis='y', direction = 'in', labelsize = 16, labelcolor=color1)
ax1.tick_params(axis='x', direction = 'in', labelsize = 16)
ax1.set_xlabel('distance from meniscus (nm)',fontsize = 16)
ax1.set_ylim(0,1.9)
ax1.set_xlim(0,500)
ax1.minorticks_off()


ax2 = ax1.twinx()
color2 = 'tab:red'
ax2.plot((r-r0)*1e9,n,'--',color = color2)
ax2.minorticks_off()
ax2.set_ylim(0,300)
ax2.set_xlabel('distance from meniscus (nm)', fontsize = 16)
ax2.set_ylabel('vapor density (mmol/m^3)', color=color2,fontsize = 16)
ax2.tick_params(axis='y', direction = 'in', labelsize = 18, color = color2, labelcolor=color2)


plt.tight_layout()



p0 = 17.5/2 * 133.32 # water vapor pressure in pascals 
p_bg = 7e-8 * 133.32  # background pressure in pascals
r0 = 30e-9 # radius of meniscus
rf = 0.5
a_i = 7e-10  # kinetic radius of amino acid with solvation shell
a_w = 1.3e-10  # kinetic radius of water molecule
a_bg = 1.8e-10  # kinetic radius of N2 molecule
kB = 1.38e-23  # Boltzmann constant
T = 300
Na = 6.022e23
r = np.logspace(np.log10(r0),np.log10(rf),1000)

sigma_w = np.pi*(a_i+a_w)**2
sigma_bg = np.pi*(a_i+a_bg)**2


n0 = p0/(kB*T)
nbg = p_bg/(kB*T)


Pc = 1-np.exp((-sigma_w*n0*r0**2 * (1/r0 - 1/r)))
Pc_bg = 1-np.exp((-sigma_bg*nbg*(r-r0)))
Pc_total = 1-np.exp((-sigma_w*n0*r0**2 * (1/r0 - 1/r) - sigma_bg*nbg*(r-r0)))


fig,ax = plt.subplots(figsize = [4,3])
ax.semilogx(r-r0,Pc_total*100,linestyle = 'solid',linewidth = 2, label = 'total')
ax.semilogx(r-r0,Pc*100,linestyle = 'dashed',linewidth = 2, label = 'water')
ax.semilogx(r-r0,Pc_bg*100, linestyle = 'dashdot', linewidth = 2, label = 'background')
ax.set_ylim(0,2.25)
ax.set_xlim(1e-9,0.5)
ax.set_xlabel('distance from meniscus (m)', fontsize = 12)
ax.set_ylabel('cumulative collision \n probability (%)', fontsize = 12)
ax.legend()
ax.grid()
plt.tight_layout()
ax.tick_params(direction = 'in', labelsize = 12)
plt.rcParams['svg.fonttype'] = 'none'



